package com.pxmeta.app.controller.user;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.collect.Maps;
import com.pxmeta.circle.service.ICircleService;
import com.pxmeta.common.core.domain.AjaxResult;
import com.pxmeta.common.utils.SecurityUtils;
import com.pxmeta.user.entity.User;
import com.pxmeta.user.entity.UserIdentify;
import com.pxmeta.user.entity.dto.VerifyCertDTO;
import com.pxmeta.user.entity.vo.SubordinateUserVO;
import com.pxmeta.user.service.IUserIdentifyService;
import com.pxmeta.user.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Api(value = "推广模块",tags = "推广模块")
@RequestMapping(value = "/subordinate")
@CrossOrigin
@RequiredArgsConstructor
public class SubordinateController {

    private final IUserService userService;


    @GetMapping("/getTotalCommission")
    @ApiOperation("获取分享总收益")
    public AjaxResult getTotalCommission() {

        Long userId = SecurityUtils.getUserId();
        String phone = userService.getById(userId).getPhone();
        Double commission = userService.getTotalCommission(phone);

        Map<String, Object> map = Maps.newHashMap();
        map.put("commission", commission);
        return AjaxResult.success(map);
    }

    @GetMapping("/getShareUserCount")
    @ApiOperation("获取分享用户总数")
    public AjaxResult getShareUserCount(){
        Long userId = SecurityUtils.getUserId();
        Long count = userService.getSubordinateCount(userId);
        Map<String, Object> map = Maps.newHashMap();
        map.put("count", count);

        return AjaxResult.success(map);
    }


    @GetMapping("/getShareWeekCommission")
    @ApiOperation("获取分享周收益")
    public AjaxResult getShareWeekCommission(){
        Long userId = SecurityUtils.getUserId();
        String phone = userService.getById(userId).getPhone();
        Double commission = userService.getWeekCommission(phone);
        Map<String, Object> map = Maps.newHashMap();
        map.put("commission", commission);
        return AjaxResult.success(map);
    }


    @GetMapping("/getShareUsers")
    @ApiOperation("获取分享用户列表")
    public AjaxResult<List<SubordinateUserVO>> getShareUsers(@RequestParam Integer page,
                                                             @RequestParam Integer size){
        Long userId = SecurityUtils.getUserId();
        String phone = userService.getById(userId).getPhone();
        IPage<SubordinateUserVO> result = userService.getSubordinateUsers(phone, page, size);
        return AjaxResult.success(result.getRecords());
    }






}
